<template>
  <van-popover v-model="showPopover" trigger="click">
    <van-button icon="photograph" @click="handlePrefer">ta的校友圈</van-button>
    <van-button icon="chat" @click="handleChat">发消息</van-button>
    <template #reference>
      <div class="userList">
        <img :src="pieceData.avator" width="50px" height="50px" />
        <p class="nickname">{{ pieceData.nickname }}</p>
      </div>
    </template>
  </van-popover>
</template>

<script>
export default {
  props: ["pieceData"],
  data() {
    return {
      showPopover: false,
    };
  },
  methods: {
    handleChat() {
      this.$store.commit("SET_CHAT_USER", {userID:this.pieceData.userID,avator:this.pieceData.avator,nickname:this.pieceData.nickname,historyList:[]});
      this.$router.push({
        path: "/chatroom",
        query: {
          userID: this.pieceData.userID,
          name: this.pieceData.nickname,
          avator: this.pieceData.avator,
        },
      });
    },
    handlePrefer() {
      this.$router.push({
        path: "/prefer",
        query: { origin: "released", userID: this.pieceData.userID },
      });
      location.reload();
    },
  },
};
</script>

<style scoped>
.userList {
  width: 100vw;
  background-color: #fafafa;
  margin: 5px 0;
  padding: 2px;
  display: flex;
}
.userList p {
  margin: auto 10px;
  font-size: 16px;
}
</style>